<?php

if(session::user() && session::user()->hasRole('ADMIN'))
{

   $CF = config::getInstance();

   $f = $REQUEST->dataPost('f');
   if(!empty($f))
   {
      foreach($f AS $k => $v)
      {
         $k = explode('__', $k);
         if(sizeof($k) == 2)
         {
            $section = $k[0];
            $name    = $k[1];

            $CF->updateConfig($section, $name, $v);
         }
      }
      echo json_encode(TRUE);
      exit();
   }

   # Display Vars
   if (session::user()->id == 1)
      $level = 1;
   else
      $level = 0;

   $blocks = $CF->getBlocks();
   $data = $CF->getSettings($level);
   $SMARTY->assign('data', $data);
   $SMARTY->assign('blocks', $blocks);
    
   $layout = 'configure.html';
} else
{
   if (session::user())
   {
      $ErrorHandler->setError(
              array(
                  'code' => 'access',
                  'varkey' => 'access_denied'
              )
      );
   }
   $layout = 'login.html';
}